import { defineStore } from 'pinia'

export const useSystemStore = defineStore('system',{
  // 动作
  actions:{
    setUserInfo(userInfo){
      this.userInfo = userInfo
    },
    quit(){
      this.userInfo = null
    },
    updateUserInfo(data){
      let userInfo = {
        ...this.userInfo,
        ...data
      }
      this.userInfo = userInfo
    }
  },
  // 状态
  state(){
    return {
      userInfo: null
    }
  },
  // 计算
  getters:{
    getUserInfo: (state) => state.userInfo,
    getPermissions: (state) => state.userInfo ? state.userInfo.permissions != null ? state.userInfo.permissions != '' ? state.userInfo.permissions.indexOf(',') != -1 ? state.userInfo.permissions.split(',') : [state.userInfo.permissions] : [] : [] : []
  },
  persist: true
})
